#include <windows.h>
#include "ConfigFile.h"

bool ConfigFile::Loaded = false;
int ConfigFile::Encrypt = 0;
int ConfigFile::DecryptAddress = 0;
int ConfigFile::PID = 0;
int ConfigFile::MaxHP = 0;
int ConfigFile::MaxMP = 0;
int ConfigFile::Level = 0;
int ConfigFile::CurrentHP = 0; 	
int ConfigFile::CurrentMP = 0; 
int ConfigFile::CurrentXP = 0; 
int ConfigFile::InGame = 0; 
int ConfigFile::Page = 0; 
int ConfigFile::HPPercent = 0; 
int ConfigFile::MPPercent = 0; 
int ConfigFile::XPPercent = 0; 
int ConfigFile::FPS = 0; 
int ConfigFile::LocationX = 0; 
int ConfigFile::LocationY = 0; 
int ConfigFile::Money = 0; 
int ConfigFile::TimeOfDay = 0;
int ConfigFile::Server = 0;
int ConfigFile::InChat = 0;
int ConfigFile::View = 0;

int ConfigFile::MapInput = 0;
int ConfigFile::StatsDisplayInput = 0;
int ConfigFile::LevelCalcInput = 0;
int ConfigFile::GoldCalcInput = 0;
int ConfigFile::FastClickInput = 0;
int ConfigFile::ItemSnifferInput = 0;
int ConfigFile::InfoBarDisplay = 0;
int ConfigFile::ItemCompass = 0;

int ConfigFile::InfoBarOpacity = 175;
int ConfigFile::MapOpacity = 175;
int ConfigFile::StatsOpacity = 175;
bool ConfigFile::RealTimeInfo = false;

void ConfigFile::Load() 
{
	if(!Loaded) {
		char directory[MAX_PATH];
		GetCurrentDirectory(sizeof(directory), directory);

		LoadMemoryLocations(directory);
		LoadInputSettings(directory);
		LoadSettings(directory);

		//Utils::Log(LOGFILE, "Config File Loaded\n");
		Loaded = true;
	}
}

void ConfigFile::LoadMemoryLocations(const char *directory) 
{
		char memoryInput[25];

		GetPrivateProfileString("Memory", "Encrypt", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		Encrypt = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "Decrypt", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		DecryptAddress = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "PID", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		PID = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "MaxHP", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		MaxHP = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "MaxMP", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		MaxMP = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "Level", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		Level = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "CurrentHP", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		CurrentHP = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "CurrentMP", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		CurrentMP = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "CurrentXP", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		CurrentXP = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "InGame", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		InGame = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "Page", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		Page = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "HPPercent", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		HPPercent = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "MPPercent", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		MPPercent = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "XPPercent", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		XPPercent = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "FPS", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		FPS = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "LocationX", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		LocationX = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "LocationY", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		LocationY = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "Money", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		Money = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "TimeOfDay", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		TimeOfDay = Utils::xtoi(memoryInput);
		GetPrivateProfileString("Memory", "Server", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		Server = Utils::xtoi(memoryInput);	
		GetPrivateProfileString("Memory", "InChat", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		InChat = Utils::xtoi(memoryInput);	
		GetPrivateProfileString("Memory", "View", "0x0", memoryInput, sizeof(memoryInput), string(string(directory) + XENERGYINI).c_str());
		View = Utils::xtoi(memoryInput);	
}

void ConfigFile::LoadInputSettings(const char *directory)
{
	char inputValue[25];

	GetPrivateProfileString("Input", "Map", "0x0", inputValue, sizeof(inputValue), string(string(directory) + XENERGYINI).c_str());
	MapInput = Utils::xtoi(inputValue);
	GetPrivateProfileString("Input", "StatsDisplay", "0x0", inputValue, sizeof(inputValue), string(string(directory) + XENERGYINI).c_str());
	StatsDisplayInput = Utils::xtoi(inputValue);
	GetPrivateProfileString("Input", "LevelCalc", "0x0", inputValue, sizeof(inputValue), string(string(directory) + XENERGYINI).c_str());
	LevelCalcInput = Utils::xtoi(inputValue);
	GetPrivateProfileString("Input", "GoldCalc", "0x0", inputValue, sizeof(inputValue), string(string(directory) + XENERGYINI).c_str());
	GoldCalcInput = Utils::xtoi(inputValue);
	GetPrivateProfileString("Input", "FastClick", "0x0", inputValue, sizeof(inputValue), string(string(directory) + XENERGYINI).c_str());
	FastClickInput = Utils::xtoi(inputValue);
	GetPrivateProfileString("Input", "ItemSniffer", "0x0", inputValue, sizeof(inputValue), string(string(directory) + XENERGYINI).c_str());
	ItemSnifferInput = Utils::xtoi(inputValue);
	GetPrivateProfileString("Input", "InfoBarDisplay", "0x0", inputValue, sizeof(inputValue), string(string(directory) + XENERGYINI).c_str());
	InfoBarDisplay = Utils::xtoi(inputValue);
	GetPrivateProfileString("Input", "ItemCompass", "0x0", inputValue, sizeof(inputValue), string(string(directory) + XENERGYINI).c_str());
	ItemCompass = Utils::xtoi(inputValue);
}

void ConfigFile::LoadSettings(const char *directory)
{
	InfoBarOpacity = GetPrivateProfileInt("Settings", "InfoBarOpacity", 175, string(string(directory) + XENERGYINI).c_str());
	MapOpacity = GetPrivateProfileInt("Settings", "MapOpacity", 175, string(string(directory) + XENERGYINI).c_str());
	StatsOpacity = GetPrivateProfileInt("Settings", "StatsOpacity", 175, string(string(directory) + XENERGYINI).c_str());
	RealTimeInfo = GetPrivateProfileInt("Settings", "RealTimeInfo", false, string(string(directory) + XENERGYINI).c_str());
}